package com.hengxinguotong.zhihuichengjian.adapter;

import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;

import com.hengxinguotong.zhihuichengjian.R;
import com.hengxinguotong.zhihuichengjian.bean.AuthorType;
import com.hengxinguotong.zhihuichengjian.widget.font.HXTextView;

import java.util.List;

import butterknife.BindView;
import butterknife.ButterKnife;

/**
 * @CopyRight 恒信国通信息科技
 * @Author wulei
 * @Date 2018/9/12
 *
 * 证书类型适配器
 */

public class AuthorTypeAdapter extends BaseAdapter {
    private List<AuthorType> mDatas;
    private LayoutInflater inflater;
    private ViewHolder holder;

    public AuthorTypeAdapter(List<AuthorType> mDatas, Context context) {
        this.mDatas = mDatas;
        this.inflater = LayoutInflater.from(context);
    }

    @Override
    public int getCount() {
        return mDatas.size();
    }

    @Override
    public Object getItem(int position) {
        return mDatas.get(position);
    }

    @Override
    public long getItemId(int position) {
        return position;
    }

    @Override
    public View getView(int position, View convertView, ViewGroup parent) {
        if(convertView == null || convertView.getTag() == null){
            convertView = inflater.inflate(R.layout.item_authortype, parent, false);
            holder = new ViewHolder(convertView);
            convertView.setTag(holder);
        }else{
            holder = (ViewHolder) convertView.getTag();
        }
        AuthorType authorType = mDatas.get(position);
        holder.nameTv.setText(authorType.getName());
        return convertView;
    }

    static class ViewHolder{
        @BindView(R.id.name_tv)
        HXTextView nameTv;

        public ViewHolder(View view) {
            ButterKnife.bind(this, view);
        }
    }
}
